package controller;

import service.AdminService;
import view.ConsoleView;

import java.util.ArrayList;

public class StudentManagerController {
    ConsoleView consoleView = new ConsoleView();
    //初始化入口
    public void index(){
        //接收loginView返回的表单数据
        ArrayList<String> form = consoleView.loginView();
        login(form);
    }
    //登录controller
    public void login(ArrayList<String> form){
        AdminService adminService = new AdminService();
        if(adminService.login(form)){
            System.out.println("登录成功");
            //跳转到菜单页面
            //num为用户选择的序号
            int num = consoleView.menuView();
            selectMenu(num);
        }else{
            System.out.println("登录失败，请重新登录");
            index();
        }
    }
    //选择菜单的controller
    public void selectMenu(int num){
        if(num<0||num>5){
            //显示错误信息
            consoleView.errorInfoView();
            //重新选择
            num = consoleView.menuView();
            selectMenu(num);
        }else{
            System.out.println("用户选择的是"+num);
            switch(num){
                case 1:
                    consoleView.addStudentView();
                    break;
                case 2:
                    consoleView.deleteStudentView();
                    break;
                case 3:
                    consoleView.updateStudentView();
                    break;
                case 4:
                    consoleView.selectStudentView();
                    break;
                case 5:
                    System.out.println("===正在退出系统===");
                    System.exit(0);
                    break;
            }
        }
    }
    //新增学生
    public void addStudent(){
        System.out.println("添加学生");
    }
    //删除学生
    public  void deleteStudent(){
        System.out.println("删除学生");
    }
    //修改学生
    public void updateStudent(){
        System.out.println("修改学生");
    }
    //查询学生
    public void selectStudent(){
        System.out.println("查询学生");
    }
}
